package com.ling.pl.security.view.role;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;
import com.ling.core.common.utils.D7PageUtils;
import com.ling.core.view.BaseView;
import com.ling.pl.security.feign.DefaultRoleService;
import com.ling.pl.security.model.DefaultRoleVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Map;

@Component("ling2.roleMaintain")
public class RoleMaintain extends BaseView {
    @Resource
    DefaultRoleService roleService;

    @DataProvider
    public void loadRoles(Page<DefaultRoleVO> page, Criteria criteria) throws Exception {
        Map<String, Object> params = D7PageUtils.buildQueryParams(criteria, page);
        params.put("type", DefaultRoleVO.NORMAL_TYPE);
        D7PageUtils.daoPageToPage(roleService.findDefaultRoleByPage(params), page);
    }


    @DataResolver
    public void saveRoles(Collection<DefaultRoleVO> roles) throws Exception {
        Map allrecodsMap = D7PageUtils.assembleDatasetMap(roles);
        roleService.saveMap(allrecodsMap);
    }

    @Expose
    public void refreshUrlSecurityMetadata() {
        roleService.refreshUrlSecurityMetadata();
    }

    @Expose
    public void refreshAllSecurityMetadata() {
        roleService.refreshAllSecurityMetadata();
    }

    @Expose
    public void refreshComponentSecurityMetadata() {
        roleService.refreshComponentSecurityMetadata();
    }
}
